﻿$(document).ready(function () {    
    $('.btn').on('click', function () {
        try {
            switch ($(this).text()) {
                case "注册":
                    // todo:前台数据验证
                    if (pre_submit_validate()) {
                        var data = {
                            _csrf: $("meta[name=x-csrf-token]").attr("content"),
                            user: $("input[name='username']").val(),
                            psw: $("input[name='password']").val(),
                            emp_name: $("input[name='emp_name']").val(),
                            emp_no: $("input[name='emp_no']").val(),
                            dpt_name: $("select[name='dpt_name']").val()[0],
                            position: $("select[name='position']").val()[0]
                        }
                        $.post('/register', data, function (data, status) {
                            var data_obj = JSON.parse(data);
                            window.document.location.href = data_obj["url"];
                        });
                    } else {
                        showModal("提示", "请按要求完成表格！");
                    }
                    break;
                case "退出":
                    window.document.location.href = "/login";
                    break;
            }
        } catch (e) {
            showModal("内部错误", e.message + "\r\n\r\n" + e.stack);
        }
    });
});